package com.mininglamp.app.util;

import org.apache.log4j.PropertyConfigurator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.base.Strings;
import com.mininglamp.app.App;

public class Log4j {

	private static final Logger log = LoggerFactory.getLogger(Log4j.class);

	public static final String LOG4J_CONFIG = "log4j.properties";
	public static final String LOG4J_CONFIG_FILE_NAME = "log4j.properties";

	private static String getLog4jconfigFilename() {
		String path = System.getProperty(LOG4J_CONFIG);
		if (Strings.isNullOrEmpty(path)) {
			path = Files.join(App.APP_DIR, LOG4J_CONFIG_FILE_NAME);
		}
		log.info("Use log4j config file: {}", path);
		return path;
	}

	public static void configure() {
		PropertyConfigurator.configure(getLog4jconfigFilename());
	}

}
